package com.wltt.product.ahuthr.service;

import com.wltt.product.ahuthr.mapper.DeptMapper;
import com.wltt.product.ahuthr.model.ResultData;
import com.wltt.product.ahuthr.model.po.DeptPO;
import com.wltt.product.ahuthr.model.vo.base.DeptVO;
import com.wltt.product.ahuthr.service.base.BaseServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;


/**
 * @ClassName: DeptServiceImpl
 * @Description: 部门信息 逻辑服务类<br/>
 * 不做业务校验，参数校验统一放到前置的Service中
 * @Date: 2024-05-17 09:03:14
 * @Author yanggl
 */
@Service(value = "deptService")
public class DeptServiceImpl extends BaseServiceImpl<DeptPO, Long> implements DeptService {

    private DeptMapper deptMapper;

    //构造方法
    public DeptServiceImpl(DeptMapper deptMapper) {
        super(deptMapper);
        this.deptMapper = deptMapper;
    }

    /**
     * 查询所有部门
     *
     * @return
     */
    @Override
    public ResultData listAllDept() {
        List<DeptPO> deptPOList = deptMapper.queryAll();
        if (CollectionUtils.isEmpty(deptPOList)) {
            return ResultData.success(new ArrayList<DeptPO>());
        }
        List<DeptVO> deptVOList = new ArrayList<>();
        for (DeptPO deptPO : deptPOList) {
            DeptVO deptVO = new DeptVO();
            deptVO.setId(deptPO.getId());
            deptVO.setDeptCode(deptPO.getDeptCode());
            deptVO.setDeptName(deptPO.getDeptName());
            deptVOList.add(deptVO);
        }
        return ResultData.success(deptVOList);
    }
}